package test

import (
	"time"

	testioc "gitee.com/flycash/simple-im/internal/test/ioc"
	"github.com/ecodeclub/ginx/gctx"
	"github.com/ecodeclub/ginx/session"
	redis2 "github.com/ecodeclub/ginx/session/redis"
)

// 初始化一下 session
func init() {
	provider := redis2.NewSessionProvider(testioc.InitRedis(), "127389584287606793", time.Hour)
	session.SetDefaultProvider(provider)
}

type SessionProvider struct{}

func (s *SessionProvider) UpdateClaims(_ *gctx.Context, _ session.Claims) error {
	return nil
}

func (s *SessionProvider) RenewAccessToken(_ *gctx.Context) error {
	// TODO implement me
	panic("implement me")
}

//nolint:nilnil // 忽略
func (s *SessionProvider) NewSession(_ *gctx.Context, _ int64, _ map[string]string, _ map[string]any) (session.Session, error) {
	return nil, nil
}

//nolint:errcheck //忽略
func (s *SessionProvider) Get(ctx *gctx.Context) (session.Session, error) {
	val, _ := ctx.Get("_session")
	return val.(session.Session), nil
}
